package hello;

public class helloWorld {

	private boolean oddsTurn;

	private printer oddPrinter;
	private printer evenPrinter;
	private String endStr;
	private boolean done;

	public helloWorld() {
		oddsTurn = false;
		done = false;
		endStr ="";
		oddPrinter = new printer("el ol", true);
		evenPrinter = new printer("hlowrd", false);

		evenPrinter.start();
		oddPrinter.start();
	}
	private class printer extends Thread {
		private String constantLetters;
		private int currentLetter;
		boolean EorO;

		public printer(String CLStr, boolean ErO) {
			currentLetter = 0;
//			constantLetters = "el ol";
			constantLetters = CLStr;
			EorO = ErO;
		}

		public void run() {
			while(!done && !(currentLetter >= constantLetters.length())) {
                //if (oddsTurn==EorO) {
				endStr=endStr+constantLetters.charAt(currentLetter++);
				////System.out.print(constantLetters.charAt(currentLetter++));
				try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
                    
                    oddsTurn = !oddsTurn;
                    if(currentLetter >= constantLetters.length()){
                        done = true;

					}
				//}
			}
		}
	}
		public static void main(String args[]) {
		helloWorld hw = new helloWorld();
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(hw.endStr);
	}
}
